package com.adamfass.tractorbeam.gameupdatelogic;

import com.adamfass.tractorbeam.Controller;
import com.adamfass.tractorbeam.GameUpdateLogic;

public class DisruptorPodGameUpdateLogic implements GameUpdateLogic {
  private final Controller controller;
  private final DisruptorPodTargeter disruptorPodTargeter;
  private final DisruptorFieldFactory disruptorFieldFactory;
  
  public DisruptorPodGameUpdateLogic(
      Controller controller, 
      DisruptorPodTargeter disruptorPodTargeter, 
      DisruptorFieldFactory disruptorFieldFactory) {
    this.controller = controller;
    this.disruptorPodTargeter = disruptorPodTargeter;
    this.disruptorFieldFactory = disruptorFieldFactory;
  }
  
  public void update(float timePerFrame) {
    disruptorPodTargeter.update();
    if (controller.disruptorPodWasFired() 
        && disruptorPodTargeter.getTargetPosition() != null) {
      // TODO(afass): Create a pod instead of creating the field directly.
      disruptorFieldFactory.addDisruptorField(
          disruptorPodTargeter.getTargetPosition(),
          disruptorPodTargeter.getTargetNormal());
    }
  }
}
